﻿@inherits RadzenComponent
@if (Visible)
{
    <img @ref="@Element" style="@Style" @attributes="Attributes" class="@GetCssClass()" src="@Url" id="@GetId()" />
}
@code {
    [Parameter]
    public string Email { get; set; }

    protected string Url
    {
        get
        {
            byte[] hash = new byte[0];

            try
            {
                hash = System.Security.Cryptography.MD5.Create()
                    .ComputeHash(System.Text.Encoding.ASCII.GetBytes(Email != null ? Email : ""));
            }
            catch
            {
                //
            }

            var md5Email = string.Join("", Enumerable.Range(0, hash.Length).Select(i => hash[i].ToString("x2")));

            var style = "retro";
            var width = "36";

            return $"https://secure.gravatar.com/avatar/{md5Email}?d={style}&s={width}";
        }
    }

    protected override string GetComponentCssClass()
    {
        return "rz-gravatar";
    }
}